;*****************************************************************************************************
;+
; NAME:
;
;      eWINDOW (Enhanced WINDOW)
;
; PURPOSE:
;
;      This is the enhanced version of the standard IDL WINDOW
;      procedure. It creates an interactive and resizeable window
;      where graphics can be displayed using the IGL enhanced version
;      of the PLOT, CONTOUR,... commands. 
;
; CALLING SEQUENCE:
;
;      eWINDOW, windowId
;
; ARGUMENTS:
;
;     WINDOWID:     The identifier of the window. Similar to the
;                   window_index argument of the WINDOW procedure.
;
;                 
; KEYWORD PARAMETERS:
;
;     NOTOOLBAR:    *IGL ADDITION* : Set this keyword to prevent
;                   adding the toolbar at the bottom of the
;                   window. Note that this disables interactive
;                   capabilities. The window will act as a regular IDL
;                   window with the only difference being the
;                   possibility to resize it.
;                   It can be useful if the toolbar takes too much time to
;                   render (typically when working remotely). The
;                   default is !IGL_D.notoolbar.
;
;    _EXTRA:        Any keyword accepted by the WINDOW procedure,
;                   except the COLORS and the RETAIN keywords. See the
;                   IDL documentation of the WINDOW procedure for more details.
;
;
; PACKAGE:
;
;    Interactive Graphics Library (IGL)
;
; AUTHORS:
;
;        RAPHAEL SADOUN
;        Graduate Student
;        Institut d'Astrophysique de Paris
;        98 bis boulevard Arago
;        75014 PARIS FRANCE
;        E-mail: raphael.sadoun@gmail.com
;
;
; MODIFICATION HISTORY:
;
;     Written by: Raphael Sadoun, 24 April 2012
;-
;*****************************************************************************************************
PRO eWINDOW, windowID, $
             TITLE=title, $
             COLOR=color, $
             XSIZE=xsize, $
             YSIZE=ysize, $
             XPOS=xpos, $
             YPOS=ypos, $                                    
             FREE=free, $
             PIXMAP=pixmap, $
             NOTOOLBAR=notoolbar

  COMPILE_OPT idl2, HIDDEN  
  ON_ERROR, 2
  
  ;; Initialize global system variables
  IGL_InitSysVars

  IF Keyword_Set(free) EQ 0 THEN BEGIN
     
     ;; The default ID is 0 
     IF (n_elements(windowID) EQ 0) THEN windowID = 0

     ;; Get the window object references
     windowObjRefs = IGL_GetSysVars('WindowObjRefs')

     ;; Make sure we have a valid identifier
     IF (windowID LT 0) OR (windowID GT 49) THEN Message, 'IGL window identifiers must be between 0 and 49.'

     ;; If the target window is already opened, we close it
     targetWindow = windowObjRefs[windowID]     
     IF OBJ_ISA_VALID(targetWindow,'IGL_Window') THEN Obj_Destroy, targetWindow
     
  ENDIF

  ;; Create a new IGL_WINDOW object
  window = obj_new('IGL_Window', $
                   window_id=windowID, $
                   window_title=title, $
                   window_color=color, $
                   window_xsize=xsize, $
                   window_ysize=ysize, $
                   xpos=xpos, $
                   ypos=ypos, $                   
                   free=free, $
                   pixmap=pixmap, $
                   notoolbar=notoolbar)

END
